/****************************************************************************
*                                                                           *
* drawshape.cpp -- template state implementation							*
*                                                                           *
* ALaRI 2008												                *
*                                                                           *
****************************************************************************/

#include "drawshape.h"

QRect CDrawShape::m_sRectBound;

void CDrawShape::adjustHandle()
{
	if (m_rectHandle.top() < m_sRectBound.top())
		m_rectHandle.moveTop(m_sRectBound.top());
	if (m_rectHandle.left() < m_sRectBound.left())
		m_rectHandle.moveLeft(m_sRectBound.left());
	if (m_rectHandle.right() > m_sRectBound.right())
		m_rectHandle.moveRight(m_sRectBound.right());
	if (m_rectHandle.bottom() > m_sRectBound.bottom())
		m_rectHandle.moveBottom(m_sRectBound.bottom());
}

void CDrawLine::computeShapeHandle()
{
	m_rectHandle = QRect(p2().x(), p2().y() - s_nShapeHandleWidthDefault, 
		s_nShapeHandleWidthDefault, s_nShapeHandleWidthDefault); 
	adjustHandle();
}

void CDrawRect::computeShapeHandle()
{
	QPoint p = m_rect.bottomRight();
	m_rectHandle = (QRect(p.x() - s_nShapeHandleWidthDefault, p.y() - s_nShapeHandleWidthDefault, 
			s_nShapeHandleWidthDefault, s_nShapeHandleWidthDefault));
	adjustHandle();
}

void CDrawEllipse::computeShapeHandle()
{
	QPoint p = m_rect.bottomRight();
	m_rectHandle = QRect(p.x() - s_nShapeHandleWidthDefault, p.y() - s_nShapeHandleWidthDefault, 
			s_nShapeHandleWidthDefault, s_nShapeHandleWidthDefault);
	adjustHandle();
}

void CDrawPoint::computeShapeHandle()
{
	QPoint p = m_rect.bottomRight();
	m_rectHandle = QRect(p.x() - s_nShapeHandleWidthPoint - 2, p.y() - s_nShapeHandleWidthPoint - 2, 
			s_nShapeHandleWidthPoint, s_nShapeHandleWidthPoint);
	adjustHandle();
}

